using System;
using System.Collections.Generic;
using System.Text;

namespace GPSNav.NET
{

	//make it generic
	/*internal*/public class GpsWaysCache : Dictionary<Int64, GpsWay>
	{
		private int maxValues = 100000;
		private List<Int64> waysIds = new List<Int64>();

		public GpsWaysCache()
			: base()
		{

		}
		public GpsWaysCache(int maxVals)
			: base()
		{
			maxValues = maxVals;
		}

		public new void Add(Int64 key, GpsWay value)
		{
			waysIds.Add(key);
			base.Add(key, value);
			Cleanup();
		}

		private void Cleanup()
		{
			if (waysIds.Count > 2 * maxValues)
			{
				int nrElemsToRemove = waysIds.Count - maxValues;
				for (int i = 0; i < nrElemsToRemove; i++)
				{
					this.Remove(waysIds [i]);
				}
				waysIds.RemoveRange(0, nrElemsToRemove);
			}
		}


	}
}
